package com.api.tag.getdepartmentsfortag;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.ITagApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.DepartmentApi;
import com.zyncro.api.model.PagedItemsResultApi;

@ContextConfiguration(locations = { "classpath:/tags/tags-context.xml" })
public class GetDepartmentsForTag extends AbstractApiTest {

	@Value("#{statictags['user.getTags'].appId}")
	private String getTagsUserUrn;

	@Value("#{statictags['user.getTags'].password}")
	private String getTagsUserPassword;

	@Value("#{statictags['category.urn']}")
	private String categoryUrn;

	@Value("#{statictags['location.urn']}")
	private String locationUrn;

	@Value("#{statictags['cant.category.departments']}")
	private int cantCategoryDepartments;

	@Value("#{statictags['cant.location.departments']}")
	private int cantLocationDepartments;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(getTagsUserUrn, getTagsUserPassword);
	}

	@Test
	public void testGetCategoryDepartments() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		PagedItemsResultApi<DepartmentApi> result = getApi().getService(ITagApiService.class).getDepartmentsForTag(categoryUrn, pageNumber,
				itemsPerPage);

		Assert.assertEquals(result.getTotalItems(), cantCategoryDepartments, "Total category departments");
	}

	@Test
	public void testGetLocationDepartments() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		PagedItemsResultApi<DepartmentApi> result = getApi().getService(ITagApiService.class).getDepartmentsForTag(locationUrn, pageNumber,
				itemsPerPage);

		Assert.assertEquals(result.getTotalItems(), cantLocationDepartments, "Total location departments");
	}
}
